﻿using FictionsDownload.DAL;
using FictionsDownload.Static;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FictionsDownload.Model
{
    [Table("Book")]
    public class BookModel:BaseModel
    {
        public enum EState
        {
            正常更新 = 1,
            停止更新
        }
        public BookModel():base()
        {
            SortOrder = System.Windows.Forms.SortOrder.Ascending;
            State = EState.正常更新;
            FolderId = FolderModel.BaseNode;
        }
        [Required]
        [Display(Name = "书名")]
        public string Name { get; set; }
        [Required]
        [Display(Name = "网站链接")]
        public string Url { get; set; }
        [Display(Name ="目录链接")]
        public string DirectoryUrl { get; set; }
        [Display(Name = "目录开头")]
        public string HtmlHead { get; set; }
        [Display(Name = "目录结尾")]
        public string HtmlTail { get; set; }
        [Display(Name = "卷名开头")]
        public string VolumeHead { get; set; }
        [Display(Name = "卷名结尾")]
        public string VolumeTail { get; set; }
        [Display(Name = "章节开头")]
        public string TextHead { get; set; }
        [Display(Name = "卷名结尾")]
        public string TextTail { get; set; }
        [Display(Name = "是否更新")]
        public EState State { get; set; }
        public string FolderId { get; set; }
        public virtual FolderModel Folder { get; set; }
        public virtual List<DirectoryModel> Directories { get; set; }
        public System.Windows.Forms.SortOrder SortOrder { get; set; }
        public void Delete(IDAL db)
        {
            db.Delete<DirectoryModel>(d => d.BookId == Id);
            db.Delete(this);
        }
    }
}
